#include "stdafx.h"
#include "NetManager.h"

#include "TempHttpPool.h"
#include "CriticalSection.h"
#include "MakePostData.h"
#include "NetJob.h"
#include "Interface.h"

#include "Data/Base64.h"
#include "Data/MD5.h"
#include "Data/CharsetConvert.h"
#include "Data/DataManager.h"
#include "Data/JsonData.h"
#include "Data/GZip.h"
#include "Data/XmlData.h"

#include "UI/UICallBack.h"

CNetManager::CNetManager()
{
	m_pHttpPool = NULL;
	m_pNetJobSection = new CriticalSection;
	m_pMakePostData = new CMakePostData;
}

CNetManager::~CNetManager()
{
	if (m_pHttpPool)
	{
		delete m_pHttpPool;
		m_pHttpPool = NULL;
	}

	if (m_pNetJobSection)
	{
		delete m_pNetJobSection;
		m_pNetJobSection = NULL;
	}

	if (m_pMakePostData)
	{
		delete m_pMakePostData;
		m_pMakePostData = NULL;
	}
}

void CNetManager::Init(int nPoolSize)
{

	m_pHttpPool = new CTempHttpPool;
	m_pHttpPool->Init(nPoolSize);
	m_pHttpPool->Start();
}

void CNetManager::SetUserInfo(const CString& strAppCode,const CString& strKey,const CString& strUserID,const CString& strToken)
{
	m_strAppCode = strAppCode;
	m_strKey = strKey;
	m_strUserID = strUserID;
	m_strToken = strToken;

	m_pMakePostData->SetUserInfo(strAppCode,strKey,strUserID,strToken);

}

void CNetManager::SetNetInfo(const CString& strIP,UINT uPort)
{
	m_strIP = strIP;
	m_uPort = uPort;

	m_pMakePostData->SetNetInfo(strIP,uPort);
}

void CNetManager::SetISpaceUrl(const CString& strISpaceUrl)
{
	m_strISpaceUrl = strISpaceUrl;
}


void CNetManager::NetJobFinish(CNetJob* pNetJob)
{
	if (pNetJob)
	{
		CString strCoding = ca2ct(pNetJob->GetCoding().c_str());
		strCoding.Trim();
		string szRet;
		if (_T("gzip") == strCoding)
		{
			char * pOut = NULL;
			int nOutLen=0;
			inflate_read(pNetJob->GetBuf(),pNetJob->GetLen(),&pOut,&nOutLen,true);
			szRet = string(pOut,nOutLen);
			free(pOut);
		}
		else if(_T("deflate") == strCoding)
		{
			ASSERT(FALSE);
			char * pOut = NULL;
			int nOutLen=0;
			inflate_read(pNetJob->GetBuf(),pNetJob->GetLen(),&pOut,&nOutLen,false);
			szRet = string(pOut,nOutLen);
			free(pOut);
		}
		else
		{
			szRet = string(pNetJob->GetBuf(),pNetJob->GetLen());
		}

		std::string szErrPage = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
		if(szRet.find(szErrPage,0) == -1)
		{
			const WebRequestMessage* pMsg= GetNetJobTaskData(pNetJob);
			if (pMsg)
			{
				OnTask(*pMsg,pNetJob,szRet);
			}
		}
		else
		{
			const WebRequestMessage* pMsg= GetNetJobTaskData(pNetJob);
			if (pMsg)
			{
				OnTask(*pMsg,pNetJob,"");
			}
		}

		

		DestoryNetJob(pNetJob);
	}
}

void CNetManager::NetJobError(CNetJob* pNetJob)
{
	int nErr = pNetJob->GetError();
	CString strTemp;
	strTemp.Format(_T("NetJob Err:%d\n"),nErr);
	OutputDebugString(strTemp);
//	DestoryNetJob(pNetJob);
}

void CNetManager::NetOnRecv(CNetJob* ,int nLen,int nTotal)
{

}


CNetJob* CNetManager::CreateNetJob(const WebRequestMessage& sData)
{
	CritScope scope(m_pNetJobSection);
	CNetJob * pJob = new CNetJob;
	pJob->Init(this);
	m_mapNetJobs[pJob]=sData;
	return pJob;

	return NULL;
}

const WebRequestMessage * CNetManager::GetNetJobTaskData(CNetJob* pNetJob)
{
	CritScope scope(m_pNetJobSection);
	map<CNetJob*,WebRequestMessage>::iterator it = m_mapNetJobs.find(pNetJob);
	if (it != m_mapNetJobs.end())
	{
		return &it->second;
	}

	return NULL;
}

bool CNetManager::DestoryNetJob(CNetJob* pNetJob)
{
	CritScope scope(m_pNetJobSection);
	map<CNetJob*,WebRequestMessage>::iterator it = m_mapNetJobs.find(pNetJob);
	if (it != m_mapNetJobs.end())
	{
		CNetJob * pJob = it->first;
		if (pJob)
		{
			delete pJob; 
		}

		//DeleteWebRequestMessageData(it->second);
		m_mapNetJobs.erase(it);

		return true;
	}

	return false;
}

void CNetManager::ClearNetJobs()
{
	CritScope scope(m_pNetJobSection);
	for (map<CNetJob*,WebRequestMessage>::iterator it = m_mapNetJobs.begin();it!= m_mapNetJobs.end();++it)
	{
		CNetJob * pJob = it->first;
		if (pJob)
		{
			delete pJob; 
		}

		//DeleteWebRequestMessageData(it->second);

	}

	m_mapNetJobs.clear();
}

#define WRCASEDELETE(x) case WebRequestType_##x:\
{\
	WebRequest##x* pData=(WebRequest##x*)sMsg.pParamData;\
	delete pData;\
	sMsg.pParamData = NULL;\
	break;\
}\


bool CNetManager::DeleteWebRequestMessageData(WebRequestMessage& sMsg)
{
	switch (sMsg.nType)
	{
		WRCASEDELETE(UploadFile)
		WRCASEDELETE(MoveFile)
		WRCASEDELETE(DeleteFile)
		WRCASEDELETE(RecoverFile)
		WRCASEDELETE(ClearRecycler)
		WRCASEDELETE(SetFilePasswd)
		WRCASEDELETE(GetFileList)
		WRCASEDELETE(TransCode)
		WRCASEDELETE(Recommend)
		WRCASEDELETE(AddDownload)
		WRCASEDELETE(GetDownload)
		WRCASEDELETE(MergeDownload)
		WRCASEDELETE(DepartDownload)
		WRCASEDELETE(Detail)
		WRCASEDELETE(CreateDir)
		WRCASEDELETE(Search)
		WRCASEDELETE(DataType)
		WRCASEDELETE(GetSize)
		WRCASEDELETE(DelDownload)
		WRCASEDELETE(RenameDownload)
		WRCASEDELETE(GetUploadRecord)
		WRCASEDELETE(TransPercent)
		WRCASEDELETE(AddYunDownload)
		WRCASEDELETE(GetOffDownload)
		WRCASEDELETE(OnlineOrder)
		WRCASEDELETE(ResetFilePasswd)
		WRCASEDELETE(ApkDown)
		WRCASEDELETE(LoginStat)
		WRCASEDELETE(DetailStat)
		WRCASEDELETE(HDPlay)
		WRCASEDELETE(MovieDetail)
		WRCASEDELETE(ThirdPartTransCode)
		WRCASEDELETE(ThirdPartHttpCTS)
		WRCASEDELETE(SearchData)
		
	}
	return false;
}

#define WRCASETASK(x) 	case WebRequestType_##x:\
{\
	x##Data *pData = new x##Data;\
	if (CDataManager::GetInstance()->GetJsonData()->Parse##x(szRet,*pData))\
	{\
		CUICallBack::GetInstance()->PostMessage(UIMsgType_##x,WebRequestType_##x,(LPARAM)pData);\
	}\
	break;\
}\

#define WRCASETASKXML(x) case WebRequestType_##x:\
{\
	x##Data sData;\
	if (CDataManager::GetInstance()->GetXmlData()->Parse##x(szRet,sData))\
	{\
		x##Data* pData = new x##Data;\
		*pData = sData;\
		CUICallBack::GetInstance()->PostMessage(UIMsgType_##x,WebRequestType_##x,(LPARAM)pData);\
	}\
	else\
	{\
		CUICallBack::GetInstance()->PostMessage(UIMsgType_##x,WebRequestType_##x,(LPARAM)NULL);\
	}\
	break;\
}\


void CNetManager::OnTask(const WebRequestMessage& sMsg,const CNetJob* pJob,const string & szRet)
{
	switch (sMsg.nType)
	{
		WRCASETASK(UploadFile)
		WRCASETASK(MoveFile)
		WRCASETASK(DeleteFile)
		WRCASETASK(RecoverFile)
		WRCASETASK(ClearRecycler)
		WRCASETASK(SetFilePasswd)
		WRCASETASK(GetFileList)
		WRCASETASK(TransCode)
		WRCASETASK(Recommend)
		WRCASETASK(AddDownload)
		WRCASETASK(GetDownload)
		WRCASETASK(MergeDownload)
		WRCASETASK(DepartDownload)
		WRCASETASK(Detail)
		WRCASETASK(CreateDir)
		WRCASETASK(Search)
		WRCASETASK(DataType)
		WRCASETASK(GetSize)
		WRCASETASK(DelDownload)
		WRCASETASK(RenameDownload)
		WRCASETASK(GetUploadRecord)
		WRCASETASK(TransPercent)
		WRCASETASK(AddYunDownload)
		WRCASETASK(GetOffDownload)
		WRCASETASK(OnlineOrder)
		WRCASETASK(ResetFilePasswd)
		WRCASETASK(ApkDown)
		WRCASETASK(LoginStat)
		WRCASETASK(DetailStat)
		WRCASETASK(HDPlay)
		WRCASETASK(MovieDetail)
		WRCASETASK(ThirdPartTransCode)
		WRCASETASK(ThirdPartHttpCTS)
		WRCASETASK(SearchData)


		WRCASETASKXML(UserSpaceProfileQuery)
		WRCASETASKXML(ISpaceUserContentQuery)
		WRCASETASKXML(UploadContentSyncRequest)
		WRCASETASKXML(UploadContentSyncNotify)
		WRCASETASKXML(NpvrOrderRequest)
		WRCASETASKXML(AddContentToUserISpace)
		WRCASETASKXML(UserAccountAuth)
		WRCASETASKXML(ContentAuthurlQuery)
		WRCASETASKXML(ISpaceUserTaskQuery)
		WRCASETASKXML(ISpaceUserContentDelete)
		WRCASETASK(ChannelScheduleQuery)
		WRCASETASK(UserPlayHistoryQuery)
		WRCASETASK(ISpaceContentDetailQuery)
		WRCASETASKXML(ISpaceContentPlayurlQuery)
	default:
		{
			CDataManager::GetInstance()->GetJsonData()->Test(szRet);
		}
		break;
		
	}
}
/************************************************************************/
/*                                                                      */
/************************************************************************/

#define  ADDNETMSG(x) WebRequestMessage sMsg;\
	sMsg.nType = WebRequestType_##x;\
	sMsg.pParamData = pData;\
	CNetJob *pJob = CreateNetJob(sMsg);\
	if (pJob)\
	{\
		return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());\
	}\


bool CNetManager::UploadFile(const CString& strFileName,DWORD dwFileSize,int nType /*= 0*/,int nParentID/*=0*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->UploadFilePostData(szUrl,szPost,strFileName,dwFileSize,nType,nParentID))
	{
		WebRequestUploadFile * pData = new WebRequestUploadFile;
		pData->strFileName;
		pData->dwFileSize;
		pData->nType;
		pData->nParentID;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_UploadFile;
		sMsg.pParamData =pData;
		CNetJob* pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
		
	}

	return false;
}

bool CNetManager::MoveFile(const CString& strFileId,const CString& strNewFileName,int nParentID/*=0*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->MoveFilePostData(szUrl,szPost,strFileId,strNewFileName,nParentID))
	{
		WebRequestMoveFile * pData = new WebRequestMoveFile;
		pData->strFileId = strFileId;
		pData->strNewFileName = strNewFileName;
		pData->nParentID = nParentID;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_MoveFile;
		sMsg.pParamData = pData;
		
		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::DeleteFile(const vector<CString>& vFileId)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->DeleteFilePostData(szUrl,szPost,vFileId))
	{
		WebRequestDeleteFile* pData = new WebRequestDeleteFile;
		pData->vFileId = vFileId;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_DeleteFile;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
		 
}

bool CNetManager::RecoverFile(const vector<CString>& vFileId)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->RecoverFilePostData(szUrl,szPost,vFileId))
	{
		WebRequestRecoverFile* pData = new WebRequestRecoverFile;
		pData->vFileId = vFileId;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_RecoverFile;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::ClearRecycler(const vector<CString>* pvFileId /*= NULL*/,int nType/*=0*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->ClearRecyclerPostData(szUrl,szPost,pvFileId,nType))
	{
		WebRequestClearRecycler* pData = new WebRequestClearRecycler;
		if (pvFileId)
		{
			pData->vFileId = *pvFileId;
		}
		
		pData->nType = nType;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_ClearRecycler;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::SetFilePasswd(const CString& strFileId,const CString& strNewPasswd/*=_T("")*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->SetFilePasswdPostData(szUrl,szPost,strFileId,strNewPasswd))
	{
		WebRequestSetFilePasswd* pData = new WebRequestSetFilePasswd;
		pData->strFileId = strFileId;
		pData->strNewPasswd = strNewPasswd;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_SetFilePasswd;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::GetFileList(int nType,const vector<CString>* pvFileId /*= NULL*/,int nParentID/*=0*/,int nIsDelete /*= 0*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->GetFileListPostData(szUrl,szPost,nType,pvFileId,nParentID,nIsDelete))
	{
		WebRequestGetFileList* pData = new WebRequestGetFileList;
		pData->nType = nType;
		if (pvFileId)
		{
			pData->vFileId = *pvFileId;
		}
		
		pData->nParentID = nParentID;
		pData->nIsDelete = nIsDelete;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_GetFileList;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	
	return false;

}

bool CNetManager::TransCode(const CString& strFileId,int nWidth/*=0*/,const CString& strClient/*=_T("")*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->TransCodePostData(szUrl,szPost,strFileId,nWidth,strClient))
	{
		WebRequestTransCode* pData = new WebRequestTransCode;
		pData->strFileId = strFileId;
		pData->nWidth = nWidth;
		pData->strClient = strClient;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_TransCode;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::Recommend(int nType,const CString& strSource /*= _T("")*/,const CString& strTime/*=_T("")*/,int nImage /*= 0*/,int nNum /*= 0*/,const CString& strClient/*=_T("")*/,int nPage /*= 0*/,int nPageSize /*= 0*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->RecommendPostData(szUrl,szPost,nType,strSource,strTime,nImage,nNum,strClient,nPage,nPageSize))
	{
		WebRequestRecommend* pData = new WebRequestRecommend;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_Recommend;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::AddDownload(int nType,int nResID)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->AddDownloadPostData(szUrl,szPost,nType,nResID))
	{
		WebRequestAddDownload* pData = new WebRequestAddDownload;
		pData->nType = nType;
		pData->nResID = nResID;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_AddDownload;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::GetDownload(int nType,const CString& strPath /*= _T("")*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->GetDownloadPostData(szUrl,szPost,nType,strPath))
	{
		WebRequestGetDownload* pData = new WebRequestGetDownload;
		pData->nType = nType;
		pData->strPath = strPath;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_GetDownload;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::MergeDownload(int nType,const CString& strPath,int nResID,int nMergeID)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->MergeDownloadPostData(szUrl,szPost,nType,strPath,nResID,nMergeID))
	{
		WebRequestMergeDownload* pData = new WebRequestMergeDownload;
		pData->nType = nType;
		pData->strPath = strPath;
		pData->nResID = nResID;
		pData->nMergeID = nMergeID;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_MergeDownload;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::DepartDownload(int nType,const CString& strPath,int nRid)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->DepartDownloadPostData(szUrl,szPost,nType,strPath,nRid))
	{
		WebRequestDepartDownload* pData = new WebRequestDepartDownload;
		pData->nType = nType;
		pData->strPath = strPath;
		pData->nRid =  nRid;


		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_DepartDownload;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::Detail(int nRid)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->DetailPostData(szUrl,szPost,nRid))
	{
		WebRequestDetail* pData = new WebRequestDetail;
		pData->nRid = nRid;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_Detail;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::CreateDir(int nType,const CString& strDirName,int nParentID/*=0*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->CreateDirPostData(szUrl,szPost,nType,strDirName,nParentID))
	{
		WebRequestCreateDir* pData = new WebRequestCreateDir;
		pData->nType = nType;
		pData->strDirName = strDirName;
		pData->nParentID = nParentID;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_CreateDir;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::NetSearch(int nQueryType,int nType,const CString& strSearch,int nChildType/*=0*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->NetSearchPostData(szUrl,szPost,nQueryType,nType,strSearch,nChildType))
	{
		WebRequestSearch* pData = new WebRequestSearch;
		pData->nQueryType = nQueryType;
		pData->nType = nType;
		pData->strSearch = strSearch;
		pData->nChildType = nChildType;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_Search;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::DataType(int nType)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->DataTypePostData(szUrl,szPost,nType))
	{
		WebRequestDataType* pData = new WebRequestDataType;
		pData->nType = nType;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_DataType;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::GetSize()
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->GetSizePostData(szUrl,szPost))
	{
		WebRequestGetSize* pData = new WebRequestGetSize;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_GetSize;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::DelDownload(const vector<int>& vId)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->DelDownloadPostData(szUrl,szPost,vId))
	{
		WebRequestDelDownload* pData = new WebRequestDelDownload;
		pData->vId = vId;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_DelDownload;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::RenameDownload(const CString& strNewName,int nId)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->RenameDownloadPostData(szUrl,szPost,strNewName,nId))
	{
		WebRequestRenameDownload* pData = new WebRequestRenameDownload;
		pData->strNewName = strNewName;
		pData->nId = nId;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_RenameDownload;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::GetUploadRecord()
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->GetUploadRecordPostData(szUrl,szPost))
	{
		WebRequestGetUploadRecord* pData = new WebRequestGetUploadRecord;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_GetUploadRecord;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::TransPercent(const CString& strFileId)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->TransPercentPostData(szUrl,szPost,strFileId))
	{
		WebRequestTransPercent* pData = new WebRequestTransPercent;
		pData->strFileId = strFileId;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_TransPercent;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::AddYunDownload(int nType,int nResId,const CString& strResName,int nResChildType,const CString& strVedioUrl,const CString& strImage,const CString& strRemark,int nFileSize )
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->AddYunDownloadPostData(szUrl,szPost,nType,nResChildType,strResName,nResChildType,strVedioUrl,strImage,strRemark,nFileSize))
	{
		WebRequestAddYunDownload* pData = new WebRequestAddYunDownload;
		pData->nType = nType;
		pData->nResId = nResId;
		pData->strResName = strResName;
		pData->nResChildType = nResChildType;
		pData->strVedioUrl = strVedioUrl;
		pData->strImage = strImage;
		pData->strRemark = strRemark;
		pData->nFileSize = nFileSize;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_AddYunDownload;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::GetOffDownload(int nMovieId)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->GetOffDownloadPostData(szUrl,szPost,nMovieId))
	{
		WebRequestGetOffDownload* pData = new WebRequestGetOffDownload;
		pData->nMovieId = nMovieId;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_GetOffDownload;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::OnlineOrder(int nMovieId,int nVideoId,int nIsOnline)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->OnlineOrderPostData(szUrl,szPost,nMovieId,nVideoId,nIsOnline))
	{
		WebRequestOnlineOrder* pData = new WebRequestOnlineOrder;
		pData->nMovieId = nMovieId;
		pData->nVideoId = nVideoId;
		pData->nIsOnline = nIsOnline;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_OnlineOrder;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;


}

bool CNetManager::ResetFilePasswd(const CString& strUserName,const CString& strPasswd,const CString& strFileId,const CString& strNewPasswd/* = _T("")*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->ResetFilePasswdPostData(szUrl,szPost,strUserName,strPasswd,strFileId,strNewPasswd))
	{
		WebRequestResetFilePasswd* pData = new WebRequestResetFilePasswd;
		pData->strUserName = strUserName;
		pData->strPasswd = strPasswd;
		pData->strFileId = strFileId;
		pData->strNewPasswd = strNewPasswd;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_ResetFilePasswd;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::ApkDown(int nApkId)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->ApkDownPostData(szUrl,szPost,nApkId))
	{
		WebRequestApkDown* pData = new WebRequestApkDown;
		pData->nApkId = nApkId;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_ApkDown;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::LoginStat(int nType)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->LoginStatPostData(szUrl,szPost,nType))
	{
		WebRequestLoginStat* pData = new WebRequestLoginStat;
		pData->nType = nType;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_LoginStat;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::DetailStat(int nType,int nResourceId)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->DetailStatPostData(szUrl,szPost,nType,nResourceId))
	{
		WebRequestDetailStat* pData = new WebRequestDetailStat;
		pData->nType = nType;
		pData->nResourceId = nResourceId;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_DetailStat;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}

	return false;
}

bool CNetManager::HDPlay(int nMovieId,int nIsGZ/*=1*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->HDPlayPostData(szUrl,szPost,nMovieId,nIsGZ))
	{
		WebRequestHDPlay* pData = new WebRequestHDPlay;
		pData->nMovieId = nMovieId;
		pData->nIsGZ = nIsGZ;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_HDPlay;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::MovieDetail(const vector<int>& vMid,const CString& strType/* = _T("")*/,int nIsGZ/*=1*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->MovieDetailPostData(szUrl,szPost,vMid,strType,nIsGZ))
	{
		WebRequestMovieDetail* pData = new WebRequestMovieDetail;
		pData->vMid = vMid;
		pData->strType = strType;
		pData->nIsGZ = nIsGZ;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_MovieDetail;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::ThirdPartTransCode(const CString& strUUId,const CString& strSrcName,const CString& strCallbackPercentUrl,const CString& strCallbackCompleteUrl,const CString& strDestName/*=_T("")*/,const CString& strDestFormat/*=_T("")*/,const CString& strDestAudio/*=_T("")*/,int nDestWidth/*=0*/,const CString& strContFormat/*=_T("")*/,const CString& strClient/*=_T("")*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->ThirdPartTransCodePostData(szUrl,szPost,strUUId,strSrcName,strCallbackPercentUrl,strCallbackCompleteUrl,strDestName,strDestFormat,strDestAudio,nDestWidth,strContFormat,strClient))
	{
		WebRequestThirdPartTransCode* pData = new WebRequestThirdPartTransCode;
		pData->strUUId = strUUId;
		pData->strSrcName = strSrcName;
		pData->strCallbackPercentUrl = strCallbackPercentUrl;
		pData->strCallbackCompleteUrl = strCallbackCompleteUrl;
		pData->nDestWidth = nDestWidth;
		pData->strClient = strClient;
		pData->strContFormat= strContFormat;
		pData->strDestAudio = strDestAudio;
		pData->strDestFormat = strDestFormat;
		pData->strDestName = strDestName;
	

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_ThirdPartTransCode;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::ThirdPartHttpCTS(const CString& strUUId,const CString& strDownUrl,int nTaskType,int nFileSize,const CString& strHash,const CString& strCallbackUrl/*=_T("")*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->ThirdPartHttpCTSPostData(szUrl,szPost,strUUId,strDownUrl,nTaskType,nFileSize,strHash,strCallbackUrl))
	{
		WebRequestThirdPartHttpCTS* pData = new WebRequestThirdPartHttpCTS;
		pData->strUUId = strUUId;
		pData->strDownUrl = strDownUrl;
		pData->nTaskType = nTaskType;
		pData->nFileSize = nFileSize;
		pData->strHash = strHash;
		pData->strCallbackUrl = strCallbackUrl;


		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_ThirdPartHttpCTS;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

bool CNetManager::NetSearchData(int nType,const CString& strSearch,int nChildType/*=0*/,int nPage /*=0*/,int nPageSize/*=0*/)
{
	CString szUrl;
	string szPost;
	if (m_pMakePostData->NetSearchDataPostData(szUrl,szPost,nType,strSearch,nChildType,nPage,nPageSize))
	{
		WebRequestSearchData* pData = new WebRequestSearchData;
		pData->nType = nType;
		pData->strSearch = strSearch;
		pData->nPage = nPage;
		pData->nPageSize = nPageSize;

		WebRequestMessage sMsg;
		sMsg.nType = WebRequestType_SearchData;
		sMsg.pParamData = pData;

		CNetJob *pJob = CreateNetJob(sMsg);
		if (pJob)
		{
			return m_pHttpPool->AddPostUrl(pJob,szUrl,szPost.c_str(),szPost.size());
		}
	}
	return false;
}

void CNetManager::Test(const CString& strUrl)
{
	WebRequestMessage sMsg;
	sMsg.nType = WebRequestType_None;
	sMsg.pParamData = NULL;
	CNetJob *pJob = CreateNetJob(sMsg);
	if (pJob)
	{
		m_pHttpPool->AddUrl(pJob,strUrl);
	}
}


/************************************************************************/
/*                                                                      */
/************************************************************************/

#define  ADDNETMSG2(x) WebRequestMessage sMsg;\
	sMsg.nType = WebRequestType_##x;\
	sMsg.pParamData = pData;\
	CNetJob *pJob = CreateNetJob(sMsg);\
	if (pJob)\
	{\
		return m_pHttpPool->AddPostUrl2(pJob,m_strISpaceUrl,szPostData.c_str(),szPostData.size());\
	}\


const CString strXmlTemplate = _T("<?xml version=\"1.0\" encoding=\"UTF-8\"?><message  version=\"1.0\"><header CorrelateID =\"1000002\" RequestSystemID =\"1\" TargetSystemID =\"1\" Action=\"REQUEST\" Command=\"%s\" Timestamp =\"%s\"/><body>%s</body></message>");

CString CNetManager::MakeXmlData(const CString& strCmd,const CString& strBody)
{
	CTime sTime = CTime::GetCurrentTime();
	CString strCurTime = sTime.Format(_T("%Y-%m-%d %H:%M:%S"));
	CString strXml;
	strXml.Format(strXmlTemplate,strCmd,strCurTime,strBody);

	return strXml;
}

bool CNetManager::UserSpaceProfileQuery(const vector<D2_6_Query>& vQuery)
{
	//CString strTemplate = _T("<?xml version=\"1.0\" encoding=\"UTF-8\"?><message  version=\"1.0\"><header CorrelateID =\"1000002\" RequestSystemID =\"1\" TargetSystemID =\"1\" Action=\"REQUEST\" Command=\"USER_SPACE_PROFILE_QUERY\" Timestamp =\"%s\"/><body>%s</body></message>");


	CString strBody = _T("<queries>");
	for (int i = 0; i < vQuery.size();i++)
	{
		const D2_6_Query &query = vQuery.at(i);
		CString strTmp=_T("<query UUID=\"%s\" SPID=\"%s\" AppID=\"%s\" AccessToken=\"%s\"></query>");
		CString strQuery;
		strQuery.Format(strTmp,query.strUUID,query.strSPID,query.strAppId,query.strAccessToken);
		strBody += strQuery;
	}
	strBody+= _T("</queries>");

	string szPostData = ct2cu(MakeXmlData(_T("USER_SPACE_PROFILE_QUERY"),strBody));

	WebRequestUserSpaceProfileQuery *pData = new WebRequestUserSpaceProfileQuery;
	pData->vQuerys = vQuery;

	/*WebRequestMessage sMsg;
	sMsg.nType = WebRequestType_UserSpaceProfileQuery;
	sMsg.pParamData = pData;

	CNetJob *pJob = CreateNetJob(sMsg);
	if (pJob)
	{
		return m_pHttpPool->AddPostUrl2(pJob,szUrl,szPostData.c_str(),szPostData.size());
	}*/

	ADDNETMSG2(UserSpaceProfileQuery)
	return false;

}


bool CNetManager::ISpaceUserContentQuery(const CString& strUUID,const CString& strAppId,D2_7_Type nType,int nPageNo,int nPageSize,const CString& strSPID ,const CString& strAccessToken ,D2_7_FileType nFileType,int nStatus,D2_7_ContentSearchType nContentSearchType)
{
	CString strTmp = _T("<query UUID=\"%s\" SPID=\"%s\" AppID=\"%s\" AccessToken=\"%s\" Status=\"%d\" Type=\"%d\" PageNo=\"%d\" PageSize=\"%d\" contentSearchType=\"%d\" FileType=\"%d\"></query>");
	CString strBody ;
	strBody.Format(strTmp,strUUID,strSPID,strAppId,strAccessToken,nStatus,(int)nType,nPageNo,nPageSize,(int)nContentSearchType,(int)nFileType);

	string szPostData = ct2cu(MakeXmlData(_T("ISPACE_USER_CONTENT_QUERY"),strBody));

	WebRequestISpaceUserContentQuery * pData = new WebRequestISpaceUserContentQuery;
	pData->strUUID = strUUID;
	pData->strAppId = strAppId;
	pData->strSPID = strSPID;
	pData->strAccessToken = strAccessToken;
	pData->nType = nType;
	pData->nPageNo = nPageNo;
	pData->nPageSize = nPageSize;
	pData->nFileType = nFileType;
	pData->nStatus = nStatus;

	ADDNETMSG2(ISpaceUserContentQuery);

	return false;
}

bool CNetManager::UploadContentSyncRequest(const D2_9_UploadContents& vUploadContents)
{

	return false; 

}

bool CNetManager::UploadContentSyncNotify(const D2_10_UploadContents& vUploadContents)
{
	return false;
}

bool CNetManager::NpvrOrderRequest(const vector<D2_11_Order>& vOrders)
{
	CString strBody = _T("<orders>");
	for (int i =0 ; i < vOrders.size() ;i++)
	{
		const D2_11_Order& order = vOrders.at(i);
		CString strTmp =_T("<order UUID=\"%s\" SPID=\"%s\" AppID=\"%s\" Action=\"%s\" Code=\"%s\"  ChannelID=\"%s\" ProgramID=\"%s\"  RecordType=\"%d\" BeginTime=\"%s\" EndTime=\"%s\" OrderTime=\"%s\" />");
		CString strOrder ;
		strOrder.Format(strTmp,order.strUUID,order.strSPID,order.strAppId,order.strAction,order.strCode,order.strChannelID,order.strProgramID,(int)order.nRecordType,order.strBeginTime,order.strEndTime,order.strOrderTime);
		strBody += strOrder;
	}

	strBody += _T("</orders>");
	string szPostData = ct2cu(MakeXmlData(_T("NPVR_ORDER_REQUEST"),strBody));


	WebRequestNpvrOrderRequest * pData = new WebRequestNpvrOrderRequest;
	pData->vOrders = vOrders;

	ADDNETMSG2(NpvrOrderRequest);

	return false;
}

bool CNetManager::AddContentToUserISpace(const vector<D2_12_Order>& vOrders)
{
	CString strBody = _T("<orders>");
	for (int i = 0 ; i < vOrders.size();i++)
	{
		const D2_12_Order& order = vOrders.at(i);
		CString strTmp = _T("<order Action=\"%s\" Code=\"%s\" UUID=\"%s\" SPID=\"%s\" AppID=\"%s\" ContentID=\"%s\" ContentName=\"%s\" ContentDesc =\"%s\" Size=\"%d\">%s</order>");

		CString strSubContents;
		for (int j = 0 ; j < order.vSubContents.size();j++)
		{
			const D2_12_SubContent& subcontent = order.vSubContents.at(j);
			CString strTmp2 = _T("<Subcontent SubcontentID =\"%s\" VideoCodec =\"%s\" Bitrate=\"%d\" ISHD=\"%d\"/>");

			CString strSubContent;
			strSubContent.Format(strTmp2,subcontent.strSubContentId,subcontent.strVideoCodec,subcontent.nBitRate,subcontent.nIsHD);

			strSubContents+=strSubContent;
		}
		
		
		CString strOrder;
		strOrder.Format(strTmp,order.strAction,order.strCode,order.strUUID,order.strSPID,order.strSPID,order.strContentId,order.strContentName,order.strContentDesc,order.nSize,strSubContents);

		strBody += strOrder;
	}
	strBody += _T("</orders>");
	string szPostData = ct2cu(MakeXmlData(_T("ADD_CONTENT_TO_USER_ISPACE"),strBody));

	WebRequestAddContentToUserISpace * pData = new WebRequestAddContentToUserISpace;
	pData->vOrders = vOrders;

	ADDNETMSG2(AddContentToUserISpace);
	return false;
}

bool CNetManager::UserAccountAuth(const vector<D2_13_Order>& vOrders)
{
	CString strBody = _T("<orders>");
	for (int i = 0 ; i < vOrders.size();i++)
	{
		const D2_13_Order& order = vOrders.at(i);
		CString strTmp=_T("<order Action=\"%s\" UUID=\"%s\" STBID=\"%s\" SPID=\"%s\" AppID=\"%s\" AccessToken=\"%s\" />");
		CString strOrder;
		strOrder.Format(strTmp,order.strAction,order.strUUID,order.strSTBID,order.strSPID,order.strAppId,order.strAccessToken);
		strBody += strOrder;
	}
	strBody += _T("</orders>");
	string szPostData = ct2cu(MakeXmlData(_T("USER_ACCOUNT_AUTH"),strBody));

	WebRequestUserAccountAuth * pData = new WebRequestUserAccountAuth;
	pData->vOrders = vOrders;

	ADDNETMSG2(UserAccountAuth);
	return false;
}

bool CNetManager::ContentAuthurlQuery(const CString& strContentId,const CString& strUUID,const CString& strAppId,D2_14_PlayTerminalApp nPlayTerminalApp,const CString& strSPID,const CString& strAccessToken )
{
	CString strTmp = _T("<query UUID=\"%s\" SPID=\"%s\" AppID=\"%s\" AccessToken=\"%s\" ContentID=\"%s\" playTerminalApp=\"%d\"></query>");
	CString strBody;
	strBody.Format(strTmp,strUUID,strSPID,strAppId,strAccessToken,strContentId,(int)nPlayTerminalApp);
	string szPostData = ct2cu(MakeXmlData(_T("CONTENT_AUTHURL_QUERY"),strBody));
	
	WebRequestContentAuthurlQuery * pData = new WebRequestContentAuthurlQuery;
	pData->strContentId = strContentId;
	pData->strUUID = strUUID;
	pData->strSPID = strSPID;
	pData->strAppId = strAppId;
	pData->nPlayTerminalApp = nPlayTerminalApp;
	pData->strAccessToken = strAccessToken;

	ADDNETMSG2(ContentAuthurlQuery);
	return false;
}

bool CNetManager::ISpaceUserTaskQuery(const CString& strUUID,const CString& strSPID,const CString& strAppID,const CString& strAccessToken,D2_15_Type nType,int nPageNo,int nPageSize,int nStatus)
{
	CString strTmp = _T("<query UUID=\"%s\" SPID=\"%s\" AppID=\"%s\" AccessToken=\"%s\" Status=\"%d\" Type=\"%d\" PageNo=\"%d\" PageSize=\"%d\"></query>");
	CString strBody;
	strBody.Format(strTmp,strUUID,strSPID,strAppID,strAccessToken,nStatus,(int)nType,nPageNo,nPageSize);
	string szPostData = ct2cu(MakeXmlData(_T("ISPACE_USER_TASK_QUERY"),strBody));

	WebRequestISpaceUserTaskQuery * pData = new WebRequestISpaceUserTaskQuery;
	pData->strUUID = strUUID;
	pData->strSPID = strSPID;
	pData->strAppID = strAppID;
	pData->strAccessToken = strAccessToken;
	pData->nType = nType;
	pData->nStatus = nStatus;
	pData->nPageNo = nPageNo;
	pData->nPageSize = nPageSize;

	ADDNETMSG2(ISpaceUserTaskQuery);
	return false;
}

bool CNetManager::ISpaceUserContentDelete(const CString& strAction,const CString& strUUID,const CString& strSPID,const CString& strAppID,const vector<CString> vContentId,const CString& strAccessToken)
{
	CString strContents = _T("<Contents>");
	for (int i = 0 ; i < vContentId.size();i++)
	{
		CString strTmp = _T("<Content ContentID=\"%s\"/>");
		CString strContent;
		strContent.Format(strTmp,vContentId.at(i));

		strContents += strContent;
	}
	strContents +=_T("</Contents>");

	CString strTmp2 = _T("<request Action=\"%s\" UUID=\"%s\" SPID=\"%s\" AppID=\"%s\" AccessToken=\"%s\">%s</request>");
	CString strBody;
	strBody.Format(strTmp2,strAction,strUUID,strSPID,strAppID,strAccessToken,strContents);
	string szPostData = ct2cu(MakeXmlData(_T("ISPACE_USER_CONTENT_DELETE"),strBody));

	WebRequestISpaceUserContentDelete * pData = new WebRequestISpaceUserContentDelete;
	pData->strAction =strAction;
	pData->strAppID = strAppID;
	pData->strSPID = strSPID;
	pData->strUUID = strUUID;
	pData->strAccessToken = strAccessToken;
	pData->vContentId = vContentId;

	ADDNETMSG2(ISpaceUserContentDelete);

	return false;
}

bool CNetManager::ChannelScheduleQuery(const CString& strUUID,const CString& strSPID,const CString& strAppID,const CString& strAccessToken,const CString& strStartTime ,const CString& strEndTime)
{
	CString strTmp = _T("?command=CHANNEL_SCHEDULE_QUERY&uuid=%s&spId=%s&appID=%s&accessToken=%s&startTime=%s&endTime=%s");
	CString strParam ;
	strParam.Format(strTmp,strUUID,strSPID,strAppID,strAccessToken,strStartTime,strEndTime);

	CString strUrl = m_strISpaceUrl + strParam;

	WebRequestChannelScheduleQuery * pData = new WebRequestChannelScheduleQuery;
	pData->strUUID = strUUID;
	pData->strSPID = strSPID;
	pData->strAppID = strAppID;
	pData->strAccessToken = strAccessToken;

	WebRequestMessage sMsg;
	sMsg.nType = WebRequestType_ChannelScheduleQuery;
	sMsg.pParamData = NULL;
	CNetJob *pJob = CreateNetJob(sMsg);
	if (pJob)
	{
		m_pHttpPool->AddUrl(pJob,strUrl);
	}

	return false;
}

bool CNetManager::UserPlayHistoryQuery(const CString& strUUID,const CString& strUserID,const CString& strSTBID,int nNum,D2_18_PlayTerminalApp nPlayTerminalApp,int nNeedBreakPoint,const CString& strAccessToken)
{
	CString strTmp = _T("{\"header\": { },\"body\": {\"request\": {\"command\": \"USER_PLAY_HISTORY_QUERY\",\"uuid\": \"%s\",\"userId\": \"%s\",\"stbId\":\"%s\",\"num\": \"%d\",\"playTerminalApp\":\"%d\",\"needBreakPoint\": \"%d\"}}}");;
	CString strBody;
	strBody.Format(strTmp,strUUID,strUserID,strSTBID,nNum,(int)nPlayTerminalApp,nNeedBreakPoint);
	string szPostData = ct2cu(strBody);

	WebRequestUserPlayHistoryQuery * pData = new WebRequestUserPlayHistoryQuery;
	pData->strUUID = strUUID;
	pData->strUserID = strUserID;
	pData->strSTBID = strSTBID;
	pData->strAccessToken = strAccessToken;
	pData->nNeedBreakPoint = nNeedBreakPoint;
	pData->nNum = nNum;
	pData->nPlayTerminalApp = nPlayTerminalApp;
	
	ADDNETMSG2(UserPlayHistoryQuery);

	return false;
}

bool CNetManager::ISpaceContentDetailQuery(const CString& strUUID,const CString& strSPID,const CString& strAppID,D2_19_PlayTerminalApp nPlayTerminalApp,const vector<CString>& vContentIds,const CString& strAccessToken )
{
	CString strContentIDs;
	for (int i = 0 ; i < vContentIds.size();i++)
	{
		strContentIDs +="\"";
		strContentIDs += vContentIds.at(i);
		strContentIDs +="\",";
	}

	strContentIDs = strContentIDs.Left(strContentIDs.GetLength() - 1);

	CString strTmp = _T("{\"header\": { },\"body\": {\"request\": {\"command\": \"ISPACE_CONTENT_DETAILS_QUERY\",\"Uuid\":\"%s\",\"spId\":\"%s\",\"appId\":\"%s\",\"contentIDs\":[%s]}}}");

	CString strBody ;
	strBody.Format(strTmp,strUUID,strSPID,strAppID,strContentIDs);
	string szPostData = ct2cu(strBody);

	WebRequestISpaceContentDetailQuery * pData = new WebRequestISpaceContentDetailQuery;
	pData->strUUID = strUUID;
	pData->strSPID = strSPID;
	pData->strAppID = strAppID;
	pData->strAccessToken  = strAccessToken;
	pData->nPlayTerminalApp = nPlayTerminalApp;
	pData->vContentIds = vContentIds;

	ADDNETMSG2(ISpaceContentDetailQuery)
	return false;
}

bool CNetManager::ISpaceContentPlayurlQuery(const CString& strUUID,const CString& strSPID,const CString& strAppID,D2_20_PlayTerminalApp nPlayTerminalApp,const CString& strContentId,const CString& strAccessToken,int nIsHD ,const CString& strCodec,const CString& strOtherParam )
{

	CString strTmp = _T("<request uuid=\"%s\" spId=\"%s\" appId=\"%s\" accessToken=\"%s\" playTerminalApp=\"%d\" contentID=\"%s\" isHD=\"%d\" codec=\"%s\" otherParam=\"%s\" />");
	CString strBody ;
	strBody.Format(strTmp,strUUID,strSPID,strAppID,strAccessToken,(int)nPlayTerminalApp,strContentId,nIsHD,strCodec,strOtherParam);
	string szPostData = ct2cu(MakeXmlData(_T("ISPACE_CONTENT_PLAYURL_QUERY"),strBody));

	WebRequestISpaceContentPlayurlQuery * pData = new WebRequestISpaceContentPlayurlQuery;
	pData->strUUID = strUUID;
	pData->strSPID = strSPID;
	pData->strAppID = strAppID;
	pData->strAccessToken = strAccessToken;
	pData->strCodec = strCodec;
	pData->strContentId = strContentId;
	pData->strOtherParam = strOtherParam;
	pData->nIsHD = nIsHD;
	pData->nPlayTerminalApp = nPlayTerminalApp;

	ADDNETMSG2(ISpaceContentPlayurlQuery)

	return false;
}
